#ifndef G_SCENE_H_12123455
#define G_SCENE_H_12123455

#include "math.h"
#include "geometry.h"
#include <jpegxx/write.hpp>
#include <vector>

class Ray;
class Object;

class Scene
{
	public:
		Scene(int width, int height) :
			primitives( 0 ),
			width( width ),
			height( height ),
			fieldOfView( 300 ) {}; // depth screen is in front of camera
		int getWidth() { return width; }
		int getHeight() { return height; }
		// distance to virtual screen (i.e. the plane the eye rays intersect to render the image)
		float getFieldOfView() { return fieldOfView; }
		void setFieldOfView( float fov ) { fieldOfView = fov; }
		Vec3 getCamCenter() { return camCenter; }
		//Primitive* getPrimitive( int n ) { return *primitive[n]; }
		Ray cam;
		void camSetup( const Vec3& origin, const Vec3& direction )
		{
			this->cam.origin = origin;
			this->cam.direction = direction;
			//fieldOfView = direction.z - origin.z;
			this->camCenter = cam.direction;
		}
	private:
		int primitives, width, height;
		float fieldOfView;
		Vec3 camCenter;
		//Primitive** primitive[100];
};

class Raster
{
	public:
		Raster(int width, int height)
		{
			this->width = width;
			this->height = height;
			//this->raster = std::vector<unsigned char>(this->width*this->height*3, 0);
		}
		int getWidth() { return width; }
		int getHeight() { return height; }
		void saveJPEG()
		{
			using jpegxx::raster_details;
			raster_details details(raster_details::rgb, this->width, this->height);
			unsigned seed;
			seed = (unsigned)time(NULL);
			srand(seed);
			char filename[50];
			sprintf(filename, "./images/out%d.jpg", seed);
			jpegxx::write_image(details, filename, this->raster.begin(), this->raster.end(), 1.0);
		}
		void push_color(const Color3& color)
		{
			this->raster.push_back(color.x);
			this->raster.push_back(color.y);
			this->raster.push_back(color.z);
		}
		std::vector<unsigned char> raster;
	private:
		int width, height;
};
#endif
